<?php 
include('../common/_const.php');
include('../common/common.php');
include('../common/checksession.php');
checksession("../index.php");
include('../../inc/conn.php');

//取得参数
$typeid=$_GET['catid'];

if(empty($typeid)){
	ShowMsg_h("错误提交参数!","../moduls/catalog_main.php");
	exit;
}

if(preg_match('/^\d*$/',$typeid)){

	$db=db_connect();//数据库连
	
	//是否有子栏目
	$sql=select_sql("*","`".PRETABLE."arctype`","`topid`='".$typeid."'");
	$rs=$db->query($sql);
	$issub=$rs->num_rows;
	if($issub!=0){
		ShowMsg_h("请先删除此栏目下的子栏目!","../moduls/catalog_main.php");
		exit;
	}
	
	//是否有这个栏目
	$sql=select_sql("*","`".PRETABLE."arctype`","`id`='".$typeid."'");
	$rs=$db->query($sql);
	$isset=$rs->num_rows;
	if($isset==0){
		ShowMsg_h("未知错误,删除失败!","../moduls/catalog_main.php");
		exit;
	}
	
	//删除操作
	$sql="DELETE FROM `".PRETABLE."arctype` WHERE `id`='".$typeid."'";
	if($db->query($sql)){
		ShowMsg_h("删除成功!","../moduls/catalog_main.php");
	}else{
		ShowMsg_h("未知错误，删除失败!","../moduls/catalog_main.php");
	}
	$db->close();
}
else{
   ShowMsg_h("错误提交参数!","../moduls/catalog_main.php");
   exit;
}
?>